//
//  GXBallGuyViewController.swift
//  BallGame
//
//  Created by GuangXiao on 16/3/23.
//  Copyright © 2016年 mac. All rights reserved.
//

import UIKit

class GXBallGuyViewController: UIViewController {


    override func viewDidLoad() {
        super.viewDidLoad()
view.backgroundColor = UIColor.blueColor()
        setupUI()
//        login()
//        self.navigationController = UINavigationController()
        
    }

    func setupUI(){
        let loginButton = UIButton()
        loginButton.backgroundColor = UIColor.redColor()
//        loginButton.titleLabel?.text = "登录融云"
//        loginButton.currentTitle = "登录融云"
        loginButton.setTitle("登录融云", forState: .Normal)
        loginButton.setTitle("登录融云", forState: .Highlighted)
        loginButton.sizeToFit()
        
        loginButton.addTarget(self, action: "login", forControlEvents: .TouchUpInside)
        
        view.addSubview(loginButton)
        
        loginButton.snp_makeConstraints { (make) -> Void in
            make.center.equalTo(view.snp_center)
        }

    }
    func login (){
        RCIM.sharedRCIM().connectWithToken("Cuih5qs96Ixb5MfYeZ4yMAameL8U+sRJ+DWi341VVVwJQXh1fLHKk7NrcHcOrb9VYbFGPkzfmF7+nQH0yqn+PA==",
            success: { (userId) -> Void in
                print("登陆成功。当前登录的用户ID：\(userId)")
                

                dispatch_async(dispatch_get_main_queue(), { () -> Void in
                    //登录成功后 跳转到会话列表界面
                    let chatList = GXTestChatListViewController()
                    self.navigationController?.pushViewController(chatList, animated: true)
                })
                
            }, error: { (status) -> Void in
                print("登陆的错误码为:\(status.rawValue)")
            }, tokenIncorrect: {
                //token过期或者不正确。
                //如果设置了token有效期并且token过期，请重新请求您的服务器获取新的token
                //如果没有设置token有效期却提示token错误，请检查您客户端和服务器的appkey是否匹配，还有检查您获取token的流程。
                print("token错误")
        })

    }
    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }
    

    /*
    // MARK: - Navigation

    // In a storyboard-based application, you will often want to do a little preparation before navigation
    override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
        // Get the new view controller using segue.destinationViewController.
        // Pass the selected object to the new view controller.
    }
    */

}
